package com.flutter.teach.flutter_view

import android.content.Context
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory

/**
 * 描述:
 * 作者:liuhaichao
 * 创建日期：2023/4/11 on 2:40 PM
 */
class MyAndroidViewFactory(private val messenger: BinaryMessenger) : PlatformViewFactory(StandardMessageCodec.INSTANCE) {

    /**
     * viewId：View 生成时会分配一个唯一 ID。
     * args：Flutter 传递的初始化参数。
     */
    override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
        val creationParams = args as Map<String, Any?>?
        when (creationParams?.get("type")) {
            AndroidViewType.PLUGIN_VIEW1.type -> {
                return MyAndroidView(context, messenger, viewId, creationParams)
            }
        }
        throw Exception("没有对应的View")
    }
}